package com.ruoyi.ctcx.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.ctcx.domain.TbInsuranceRiskExpert;
import com.ruoyi.ctcx.domain.TbInsuranceRiskReport;
import com.ruoyi.ctcx.domain.ro.InsuranceParam;
import com.ruoyi.ctcx.domain.ro.InsuranceQueryParam;
import com.ruoyi.ctcx.domain.vo.TbInsuranceRiskDetailVo;
import com.ruoyi.ctcx.domain.vo.TbInsuranceRiskVo;
import com.ruoyi.ctcx.service.ITbInsuranceRiskExpertService;
import com.ruoyi.ctcx.service.ITbInsuranceRiskReportService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ctcx.domain.TbInsuranceRisk;
import com.ruoyi.ctcx.service.ITbInsuranceRiskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 保险风控信息Controller
 * 
 * @author ruoyi
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/insurance/risk")
public class TbInsuranceRiskController extends BaseControllerExt
{
    @Autowired
    private ITbInsuranceRiskService tbInsuranceRiskService;

    @Autowired
    private ITbInsuranceRiskReportService tbInsuranceRiskReportService;

    @Autowired
    private ITbInsuranceRiskExpertService tbInsuranceRiskExpertService;

    /**
     * 查询保险风控信息列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:risk:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsuranceParam insuranceParam)
    {
        initDeptId(insuranceParam);
        startPage();
        List<TbInsuranceRiskVo> list = tbInsuranceRiskService.selectTbInsuranceRiskList(insuranceParam);
        return getDataTable(list);
    }

    /**
     * 导出保险风控信息列表
     */
    @PreAuthorize("@ss.hasPermi('insurance:risk:export')")
    @Log(title = "保险风控信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InsuranceParam insuranceParam)
    {
        initDeptId(insuranceParam);
        List<TbInsuranceRiskVo> list = tbInsuranceRiskService.selectTbInsuranceRiskList(insuranceParam);
        ExcelUtil<TbInsuranceRiskVo> util = new ExcelUtil<TbInsuranceRiskVo>(TbInsuranceRiskVo.class);
        util.exportExcel(response, list, "保险风控信息数据");
    }

    /**
     * 获取保险风控信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:risk:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tbInsuranceRiskService.selectTbInsuranceRiskById(id));
    }


    @GetMapping("/getRiskDetail")
    public AjaxResult getRiskDetail(InsuranceQueryParam insuranceQueryParam)
    {
        TbInsuranceRiskDetailVo tbInsuranceRiskDetailVo  = tbInsuranceRiskService.selectTbInsuranceRiskByInsureId(insuranceQueryParam);
        if (null != tbInsuranceRiskDetailVo && null != tbInsuranceRiskDetailVo.getId())
        {
            TbInsuranceRiskReport qReport = new TbInsuranceRiskReport();
            qReport.setRiskId(tbInsuranceRiskDetailVo.getId());
            List<TbInsuranceRiskReport> reportList = tbInsuranceRiskReportService.selectTbInsuranceRiskReportList(qReport);
            if (null != reportList)
            {
                tbInsuranceRiskDetailVo.setReportList(reportList);
            }

            TbInsuranceRiskExpert qExpert = new TbInsuranceRiskExpert();
            qExpert.setRiskId(tbInsuranceRiskDetailVo.getId());
            List<TbInsuranceRiskExpert> expertList = tbInsuranceRiskExpertService.selectTbInsuranceRiskExpertList(qExpert);
            if (null != expertList)
            {
                tbInsuranceRiskDetailVo.setExpertList(expertList);
            }

        }
        return success(tbInsuranceRiskDetailVo);
    }

    /**
     * 新增保险风控信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:risk:add')")
    @Log(title = "保险风控信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbInsuranceRisk tbInsuranceRisk)
    {
        tbInsuranceRisk.setCreateBy(getUsername());
        return toAjax(tbInsuranceRiskService.insertTbInsuranceRisk(tbInsuranceRisk));
    }

    /**
     * 修改保险风控信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:risk:edit')")
    @Log(title = "保险风控信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbInsuranceRisk tbInsuranceRisk)
    {
        tbInsuranceRisk.setUpdateBy(getUsername());
        return toAjax(tbInsuranceRiskService.updateTbInsuranceRisk(tbInsuranceRisk));
    }

    /**
     * 删除保险风控信息
     */
    @PreAuthorize("@ss.hasPermi('insurance:risk:remove')")
    @Log(title = "保险风控信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tbInsuranceRiskService.deleteTbInsuranceRiskByIds(ids));
    }
}
